//
//  LRSPlayerCard.swift
//  LaiLang
//
//  Created by David on 2017/2/19.
//  Copyright © 2017年 David. All rights reserved.
//

import UIKit

enum LRSCharacter{
    case wereWolves
    case villager
    case seer
    case thief
    case hunter
    case cupido
    case littleGril
    case sheriff
    
}
//4张狼人(Werewolves)
//13张普通村民(Ordinary Townsfolk/villager)
//1张预言家(Fortune Teller/Seer)
//1张盗贼(Thief)
//1张猎人(Hunter)
//1张丘比特(Cupido)
//1张女巫(Witch)
//1张小女孩(Little Girl)
//1张警长标志牌(Sheriff)

class LRSPlayerCard: UIView {

    private var _character: LRSCharacter?
    private var _shenfen: String?
    private var _id: Int?
    
    private var _nickname: String?
    
    var character: LRSCharacter?{
        get{
            return _character
        }
        set(c){
            _character = c
//            characterView.image
            
        }
    }
    
    var shenfen: String?{
        get{
            return _shenfen
        }
        set(s){
            _shenfen = s
            print("身份: \(s ?? "出错")")
            if s != nil{
                switch s! {
                case "狼人":
                    characterView.image = #imageLiteral(resourceName: "LRS_langren")
                    break
                case "村民":
                    characterView.image = #imageLiteral(resourceName: "LRS-villager")
                    break
                case "猎人":
                    characterView.image = #imageLiteral(resourceName: "LRS-hunter")
                    break
                case "预言家":
                    characterView.image = #imageLiteral(resourceName: "LRS-seer")
                    break
                default:
                    characterView.image = #imageLiteral(resourceName: "LRS-player")
                    break
                }
            }else{
                activeBtn.setTitle("出错", for: .normal)
            }
//            characterView.image = #imageLiteral(resourceName: "LRS_langren")
            //TODO: 身份牌图片
        }
    }
    
    var id : Int?{
        get{
            return _id
        }
        set(i){
            _id = i
            if i != nil{
                idLabel.text = "\(i!)"
            }
        }
    }
    
    var nickname : String?{
        get{
            return _nickname
        }
        set(i){
            _nickname = i
            nickNameLabel.text = i
        }
    }
    
    var activeBtn: UIButton!
    var characterView: UIImageView!
    
    var idLabel: UILabel!
    
    var nickNameLabel: UILabel!
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        layer.cornerRadius = 8
        layer.masksToBounds = true
        backgroundColor = UIColor.white
        
        activeBtn = UIButton(frame: CGRect(x: 0, y: 0, width: frame.width, height: frame.height - 64))
        activeBtn.backgroundColor = UIColor.lightGray
        activeBtn.setImage(#imageLiteral(resourceName: "LRS-player"), for: .normal)
        activeBtn.imageView?.contentMode = .scaleAspectFill
        activeBtn.adjustsImageWhenHighlighted = false
        addSubview(activeBtn)
        
        characterView = UIImageView(frame: CGRect(x: 0, y: 0, width: frame.width, height: frame.height - 64))
        characterView.backgroundColor = UIColor.lightGray
        characterView.contentMode = .scaleAspectFill
        characterView.layer.masksToBounds = true
        characterView.alpha = 0
        addSubview(characterView)
        
        idLabel = UILabel(frame: CGRect(x: 16, y: frame.height - 64 + 8, width: 40, height: 40))
        idLabel.layer.cornerRadius = 20
        idLabel.backgroundColor = LRSThemeColor2
        idLabel.layer.masksToBounds = true
        idLabel.textColor = UIColor.white
        idLabel.textAlignment = .center
        addSubview(idLabel)
        
        nickNameLabel = UILabel(frame: CGRect(x: 64, y: frame.height - 64 + 18, width: frame.width - 32 - 40, height: 20))
        nickNameLabel.font = UIFont.boldSystemFont(ofSize: 16)
        addSubview(nickNameLabel)
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    /*
    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code
    }
    */

}
